﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Baby.VideoConvertor
{
    public class FlvInfo
    {
        public FlvInfo()
        {
            Header = new FLVHeader();
            TagList = new List<FLVTag>();
        }
        public FLVHeader Header { get; private set; }
        public List<FLVTag> TagList { get; private set; }
        public TimeSpan Time
        {
            get
            {
                //int time = 0;
                //foreach (FLVTag tag in this.TagList.Where(p=>p.Type))
                //{ 
                //    byte[] tmp = new byte[4];
                //    tmp[3] = tag.TimeEx;
                //    tmp[0] = tag.Time[2];
                //    tmp[1] = tag.Time[1];
                //    tmp[2] = tag.Time[0];
                //    time += BitConverter.ToInt32(tmp,0);
                //}
                FLVTag tag = this.TagList.Where(p => p.Type == 9).Last();
                byte[] tmp = new byte[4];
                tmp[3] = tag.TimeEx;
                tmp[0] = tag.Time[2];
                tmp[1] = tag.Time[1];
                tmp[2] = tag.Time[0];
                return new TimeSpan(0, 0, 0, 0, BitConverter.ToInt32(tmp, 0));
            }
        }

        public double TimeDuration
        {
            get { return Time.TotalSeconds; }
        }
    }
}
